<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" />
    <title>layui</title>
    <meta name="renderer" content="webkit" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
    <meta
      name="viewport"
      content="width=device-width, initial-scale=1, maximum-scale=1"
    />
    <link
      rel="stylesheet"
      href="../../lib/layui-v2.5.5/css/layui.css"
      media="all"
    />
    <link rel="stylesheet" href="../../css/public.css" media="all" />
  </head>
  <style>
    td .layui-form-select {
      margin-top: -10px;
      margin-left: -15px;
      margin-right: -15px;
    }
  </style>
  <body>
    <div class="layuimini-container">
      <div class="layuimini-main">
        <div style="margin: 10px 10px 10px 10px">
          <form class="layui-form layui-form-pane" action="">
            <div class="layui-form-item">
              <div class="layui-inline" style="margin-left: 5%">
                <label class="layui-form-label">巡检时间</label>
                <div class="layui-input-inline">
                  <input
                    type="text"
                    name="time_xun"
                    autocomplete="off"
                    disabled
                    class="layui-input"
                  />
                </div>
              </div>
              <div class="layui-inline" style="margin-left: 30%">
                <label class="layui-form-label">巡检人员</label>
                <div class="layui-input-inline">
                  <input
                    type="text"
                    name="people"
                    placeholder="巡检人员名称"
                    autocomplete="off"
                    class="layui-input"
                  />
                </div>
              </div>
            </div>
          </form>
        </div>
        <div id="Myloading">
          <img
            src="../../lib/layui-v2.5.5/css/modules/layer/default/loading-01.gif"
            alt=""
          />
        </div>

        <script type="text/html" id="toolbarDemo">
          <div class="layui-btn-container">
            <button class="layui-btn layui-btn-sm data-add-btn" lay-event="add">
              新增数据
            </button>
          </div>
        </script>

        <table
          class="layui-hide"
          id="currentTableId"
          lay-filter="currentTableFilter"
        ></table>

        <script type="text/html" id="currentTableBar">
          <a lay-event="edit"><img src="../../images/icon-qxt.png" alt="" /></a>
        </script>

        <script type="text/html" id="remark_temp">
          <input
            type="text"
            lay-vertype="tips"
            id="k_{{d.LAY_TABLE_INDEX}}"
            placeholder="{{d.placeholder}}"
            autocomplete="off"
            class="layui-input"
            name="remark"
            lay-event="editRemark"
          />
          <!-- <input type="text" onkeyup="value=value.replace(/[^\d]/g,'')" lay-vertype="tips" id="k_{{d.LAY_TABLE_INDEX}}" placeholder="{{d.placeholder}}" autocomplete="off" class="layui-input" name="remark" lay-event="editRemark"> -->
        </script>
      </div>
    </div>
    <script src="../../lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
    <script src="../../js/lay-config.js?v=1.0.4" charset="utf-8"></script>
    <script>
      layui.use(["form", "table", "miniTab"], function () {
        // 2020-03-25 HF 保存token
        var token = sessionStorage.getItem("newtoken");
        var x_j = {};
        var device_code = null;

        var $ = layui.jquery,
          form = layui.form,
          miniTab = layui.miniTab,
          table = layui.table;
        miniTab.listen();

        let nowtime = new Date();
        var s1 = GMTToStr(nowtime);
        $("input[name='time_xun']").val(s1);

        var data = [
          {
            name: "避雷器",
            que: "瓷套表面清洁度是否正常？",
            field: "1",
            flag: "insulatorSurfaceStatus",
            placeholder: "填写0或1，其中1=正常，0=异常",
          },
          {
            name: "避雷器",
            que: "有无放电现象和痕迹？",
            field: "2",
            flag: "pdStatus",
            placeholder: "填写0或1，其中1=无，0=有",
          },
          {
            name: "避雷器",
            que: "瓷套及法兰有无裂纹、破损？",
            field: "3",
            flag: "insulatorDamageStatus",
            placeholder: "填写0或1，其中1=无，0=有",
          },
          {
            name: "避雷器",
            que: "避雷器内部是否存在异常声响？",
            field: "4",
            flag: "internalSoundStatus",
            placeholder: "填写0或1，其中1=正常，0=异常",
          },
          {
            name: "避雷器",
            que: "接地引下线是否烧伤痕迹或断股？",
            field: "5",
            flag: "groundingWireStatus",
            placeholder: "填写0或1，其中1=否，0=是",
          },
          {
            name: "避雷器",
            que: "计数器内部是否有积水？",
            field: "6",
            flag: "counterStatus",
            placeholder: "填写0或1，其中1=无，0=有",
          },
          {
            name: "避雷器",
            que: "避雷器均压环是否发生歪斜？",
            field: "7",
            flag: "strappingStatus",
            placeholder: "填写0或1，其中1=否，0=是",
          },
          {
            name: "避雷器",
            que: "运行状态",
            field: "1",
            flag: "runningStatus",
            placeholder: "填写0或1，其中1=正常，0=异常",
          },
          {
            name: "避雷器",
            que: "泄露电流监测",
            field: "1",
            flag: "leakageCurrent",
            placeholder: "≤5mA",
          },
          {
            name: "避雷器",
            que: "记录动作次数",
            field: "1",
            flag: "actionNums",
            placeholder: "填写次数",
          },
        ];

        table.render({
          elem: "#currentTableId",
          toolbar: "#toolbarDemo",
          data: data,
          defaultToolbar: [
            "filter",
            "exports",
            "print",
            {
              title: "提示",
              layEvent: "LAYTABLE_TIPS",
              icon: "layui-icon-tips",
            },
          ],

          cols: [
            [
              //复选框 {type: "checkbox", width: 50, fixed: "left"},
              { type: "numbers", width: 120, title: "序号", align: "center" },
              { field: "name", width: 150, title: "类型", align: "center" },
              { field: "que", minWidth: 110, title: "状况", align: "center" },
              {
                field: "remark",
                title: "数值",
                width: 300,
                align: "center",
                templet: "#remark_temp",
              },
              {
                title: "操作",
                width: 200,
                templet: "#currentTableBar",
                fixed: "right",
                align: "center",
              },
            ],
          ],
          limits: [10, 15, 20, 25, 50, 100],
          limit: 105,
          page: false,
          done: function (res) {
            if (res.code == -1) {
              window.location = "../login-1.html";
            }
            // 表格渲染完成回调
            $("#Myloading").remove();
          },
        });

        /**
         * toolbar监听事件
         */
        table.on("toolbar(currentTableFilter)", function (obj) {
          console.log(obj, "arrester_add");
          // 获取设备code
          device_code = sessionStorage.getItem("HsaveOverHaul_code");
          // 获取dom名称
          x_j.patrolDate = $("input[name='time_xun']").val();
          // 是否为空
          if ($("input[name='people']").val() == "") {
            x_j.patrolStaff = "operate";
          } else {
            x_j.patrolStaff = $("input[name='people']").val();
          }
          x_j.deviceCode = device_code;
          if ($("#k_0").val() == "" || $("#k_0").val() == "0") {
            x_j.insulatorSurfaceStatus = "0";
          } else {
            x_j.insulatorSurfaceStatus = "1";
          }
          if ($("#k_1").val() == "" || $("#k_1").val() == "0") {
            x_j.pdStatus = "0";
          } else {
            x_j.pdStatus = "1";
          }
          if ($("#k_2").val() == "" || $("#k_2").val() == "0") {
            x_j.insulatorDamageStatus = "0";
          } else {
            x_j.insulatorDamageStatus = "1";
          }
          if ($("#k_3").val() == "" || $("#k_3").val() == "0") {
            x_j.internalSoundStatus = "0";
          } else {
            x_j.internalSoundStatus = "1";
          }
          if ($("#k_4").val() == "" || $("#k_4").val() == "0") {
            x_j.groundingWireStatus = "0";
          } else {
            x_j.groundingWireStatus = "1";
          }
          if ($("#k_5").val() == "" || $("#k_5").val() == "0") {
            x_j.counterStatus = "0";
          } else {
            x_j.counterStatus = "1";
          }
          if ($("#k_6").val() == "" || $("#k_6").val() == "0") {
            x_j.strappingStatus = "0";
          } else {
            x_j.strappingStatus = "1";
          }
          if ($("#k_7").val() == "" || $("#k_7").val() == "0") {
            x_j.runningStatus = "0";
          } else {
            x_j.runningStatus = "1";
          }
          if ($("#k_8").val() == "" || $("#k_8").val() == "0") {
            x_j.leakageCurrent = "0";
          } else {
            x_j.leakageCurrent = $("#k_8").val();
          }
          if ($("#k_9").val() == "" || $("#k_9").val() == "0") {
            x_j.actionNums = "0";
          } else {
            x_j.actionNums = $("#k_9").val();
          }
          layer.confirm(
            "确定增加该数据吗？",
            {
              btn: ["确定", "取消"], //按钮
            },
            function () {
              add_arrester(x_j);
            }
          );
        });

        //监听表格复选框选择
        table.on("checkbox(currentTableFilter)", function (obj) {});

        // 获取列表data
        table.on("tool(currentTableFilter)", function (obj) {
          if (obj.event === "edit") {
            sessionStorage.setItem("HsaveOverHaul_flag", obj.data.flag);
            sessionStorage.setItem("HsaveOverHaul_ms", obj.data.que);

            var index = layer.open({
              title: "新增配置",
              type: 2,
              shade: 0.2,
              maxmin: true,
              shadeClose: true,
              area: ["80%", "80%"],
              content: "./line_x/line_xj.html",
              // content: ['./line_x/line_xj.html','no'] //滚动条
            });
          } else if (obj.event === "edit") {
          }
        });
        // 新增接口
        function add_arrester(x_j) {
          $.ajax({
            url: "/oms-web/patrols/arrester/authority?token=" + token,
            dataType: "json",
            type: "post",
            data: JSON.stringify(x_j),
            contentType: "application/json",
            success: function (data) {
              if (data.code == -1) {
                window.location = "../login-1.html";
              }
              if (data.code === 0) {
                layer.msg(data.msg, { icon: 1, time: 1500 }, function () {
                  parent.layer.close(iframeIndex);
                  window.parent.location.reload(); //修改成功后刷新父界面
                });
              } else {
                layer.msg(data.msg, { icon: 1, time: 1000 });
              }
            },
            error: function () {
              layer.msg("数据请求错误！");
              layer.close(index);
            },
          });
        }
        var iframeIndex = parent.layer.getFrameIndex(window.name);
      });

      function GMTToStr(time) {
        function add0(m) {
          return m < 10 ? "0" + m : m;
        } //避免少0
        var time = new Date(time);
        var year = time.getFullYear();
        var month = time.getMonth() + 1;
        var date = time.getDate();
        var hours = time.getHours();
        var minutes = time.getMinutes();
        var seconds = time.getSeconds();
        return (
          year +
          "-" +
          add0(month) +
          "-" +
          add0(date) +
          " " +
          add0(hours) +
          ":" +
          add0(minutes) +
          ":" +
          add0(seconds)
        );
      }
    </script>
  </body>
</html>
